//
// created by zhangyan, all rights reserved.
//

#ifndef __DIYLANE_BUSINESS_SERVICE_RESULT_H
#define __DIYLANE_BUSINESS_SERVICE_RESULT_H

#include <string>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/pointer.h>
#include "error.hpp"

namespace diylane
{
namespace service
{
struct Result
{
    rapidjson::Document d;

    Result()
    {
        setError(DLE_OK, "success");
    }
    ~Result()
    {
    }

    void setError(int status, std::string msg) {
        setError(status, msg.c_str());
    }

    void setError(int status, const char* msg) {
        rapidjson::SetValueByPointer(d, "/status", status);
        rapidjson::SetValueByPointer(d, "/msg", msg);
    }

    std::string dump()
    {
        rapidjson::StringBuffer buffer;
        rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
        d.Accept(writer);
        return buffer.GetString();
    }
};
}
}

#endif
